using UnityEngine;
using System.Collections;

//wraper class of normal int for HP calculation and sub/pub pattern of hp change
[System.Serializable]
public class MonitoredInt
{
	public MonitoredInt(int value)
	{
		_value = value;
	}

	[SerializeField] private int _value;
	public int Value
	{
		get { return _value; }
		set 
		{
			int lastValue = _value;
			_value = value;

			if(OnValueChanged != null)
			{
				OnValueChanged(value, lastValue);
			}
		}
	}
	
	public delegate void OnValueChangedDelegate(int newValue, int lastValue);
	public event OnValueChangedDelegate OnValueChanged;
	
	public static implicit operator int(MonitoredInt value)
	{
		return value._value;
	}

	public static bool operator == (MonitoredInt a, MonitoredInt b)
	{
		return a._value == b._value;
	}

	public static bool operator != (MonitoredInt a, MonitoredInt b)
	{
		return a._value != b._value;
	}
	
	public static bool operator < (MonitoredInt a, MonitoredInt b)
	{
		return a._value < b._value;
	}

	public static bool operator <= (MonitoredInt a, MonitoredInt b)
	{
		return a._value <= b._value;
	}

	public static bool operator > (MonitoredInt a, MonitoredInt b)
	{
		return a._value > b._value;
	}
	
	public static bool operator >= (MonitoredInt a, MonitoredInt b)
	{
		return a._value >= b._value;
	}

	public static int operator + (MonitoredInt a, MonitoredInt b)
	{
		return a._value + b._value;
	}

	public static int operator - (MonitoredInt a, MonitoredInt b)
	{
		return a._value - b._value;
	}

	public static int operator * (MonitoredInt a, MonitoredInt b)
	{
		return a._value * b._value;
	}

	public static int operator / (MonitoredInt a, MonitoredInt b)
	{
		return a._value / b._value;
	}

	public override string ToString ()
	{
		return _value.ToString();
	}
}

